package com.shoplink.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.shoplink.launcher.R;

public class MyToast extends Toast {
	private static final int LONG_DURATION_LIMIT = 10;

	public MyToast(Context context) {
		super(context);
	}

	public static MyToast makePrompt(Context context, CharSequence text) {
		MyToast myToast = new MyToast(context);
		LayoutInflater inflate = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflate.inflate(R.layout.my_toast, null);
		TextView tv = (TextView) view.findViewById(R.id.message);
		tv.setText(text);
		myToast.setView(view);
		if (text != null && text.length() >= LONG_DURATION_LIMIT) {
			myToast.setDuration(Toast.LENGTH_LONG);
		} else {
			myToast.setDuration(Toast.LENGTH_SHORT);
		}
		return myToast;
	}

	public static MyToast makePrompt(Context context, int textId) {
		MyToast myToast = new MyToast(context);
		LayoutInflater inflate = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflate.inflate(R.layout.my_toast, null);
		TextView tv = (TextView) view.findViewById(R.id.message);
		String text = context.getString(textId);
		tv.setText(textId);
		myToast.setView(view);
		if (text != null && text.length() >= LONG_DURATION_LIMIT) {
			myToast.setDuration(Toast.LENGTH_LONG);
		} else {
			myToast.setDuration(Toast.LENGTH_SHORT);
		}
		return myToast;
	}

}
